package com.itheima.Test21;

import java.io.*;
import java.util.Scanner;
import java.util.TreeSet;
@SuppressWarnings("all")
public class Demo {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        TreeSet<Student> set = new TreeSet<>();
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("Test02\\b.txt"));
        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("Test02\\b.txt"));
        for (int i = 1; i <= 3; i++) {
            System.out.println("请录入第" + i + "个学生信息:");
            Scanner sc = new Scanner(System.in);
            System.out.println("姓名:");
            String name = sc.next();
            System.out.println("语文成绩:");
            int ch = sc.nextInt();
            System.out.println("数学成绩:");
            int math = sc.nextInt();
            System.out.println("英语成绩:");
            int eng = sc.nextInt();
            Student stu = new Student(name, ch, math, eng);
            set.add(stu);
        }
        System.out.println("数据写入文件完毕");

        oos.writeObject(set);
        oos.flush();


        Object obj = ois.readObject();
        TreeSet<Student> stu = (TreeSet<Student>)obj;
        for (Student s : stu) {
            System.out.println(s.getName()+","+s.getCh()+","+s.getMath()+","+s.getEng());
        }
        ois.close();
    }
}
